import 'package:concierge/config/config.gen.dart';
import 'package:get/get.dart';
import 'package:get/get_connect/http/src/request/request.dart';

class LifeApiProvider extends GetConnect {
  @override
  void onInit() {
    super.onInit();
    // httpClient.defaultDecoder = BaseResponse.fromJson;
    httpClient.baseUrl = yamlMap.env.env_list
        .firstWhere((m) => m.type == yamlMap.env.current_env)
        .LIFE_URL;
    httpClient.maxAuthRetries = 3;
    httpClient.timeout = Duration(minutes: 1);
    httpClient.addRequestModifier((Request<dynamic> request) async {
      request.headers['corp'] = 'vertu';
      request.headers['accept-language'] =
          "${Get.locale?.languageCode}-${Get.locale?.countryCode}";
      print(
        "emmmm:[${request.method.toUpperCase()}]请求:${request.url.toString()}",
      );
      print("emmmmm:[开始时间]${DateTime.now().toString()}");
      return request;
    });
    httpClient.addResponseModifier((
      Request<dynamic> request,
      Response<dynamic> response,
    ) async {
      print("emmmmm:[结束时间]${DateTime.now().toString()}");
      return response;
    });
  }

  Future<Response<T>> get_<T>(url, {Map<String, String>? headers}) async =>
      await get<T>(url, headers: headers);
  Future<Response<T>> post_<T>(
    url,
    body, {
    Map<String, String>? headers,
    String? contentType,
    Decoder<T>? decoder,
  }) async => await post<T>(
    url,
    body,
    headers: headers,
    contentType: contentType,
    decoder: decoder,
  );
}
